import codeIcon from '../assets/icons/code.svg?raw';
import shieldIcon from '../assets/icons/shield.svg?raw';
import { createMenuItem, onTrackMenu, showMenuItem } from '../glue/ui/menu';
import { createButtonElement } from '../glue/ui/sidebar';
import { getAuthToken } from '../services';

export const copyAuthButtonEl = createButtonElement('Copy Authorization', shieldIcon);

copyAuthButtonEl.addEventListener('click', async () => {
	GM.setClipboard(await getAuthToken());
});

onTrackMenu((menuEl, trackId) => {
	const copyTrackIdButtonEl = createMenuItem('Copy ID', codeIcon);

	copyTrackIdButtonEl.addEventListener('click', () => {
		GM.setClipboard(trackId);
	});

	showMenuItem(menuEl, copyTrackIdButtonEl);
});
